package alogrithm;

/**
 * @author lbw
 * @version 1.0
 * @date 2021/11/8 17:22
 */
public class Hint {

    private static ThreadLocal<Integer> local = new ThreadLocal<>();

    public String getHint(String secret, String guess) {
        StringBuilder stringBuilder = new StringBuilder();
        int[] cntS = new int[10];
        int[] cntG = new int[10];
        int n = secret.length();
        int bulls = 0;
        int cows = 0;
        for (int i = 0; i < secret.length(); ++i) {
            if (secret.charAt(i) == guess.charAt(i)) {
                bulls++;
            } else {
                cntS[secret.charAt(i) - '0']++;
                cntG[guess.charAt(i) - '0']++;
            }
        }
        for (int i = 0; i < 10; ++i) {
            cows += Math.min(cntS[i], cntG[i]);
        }
        return stringBuilder.append(bulls).append("A").append(cows).append("B").toString();

    }
}
